package com.clgc.eduservice.config.security;

import com.clgc.eduservice.entity.EduStudent;
import com.clgc.eduservice.entity.EduTeacher;
import com.clgc.eduservice.service.EduStudentService;
import com.clgc.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailsService implements org.springframework.security.core.userdetails.UserDetailsService {
    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduStudentService eduStudentService;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        EduTeacher teacher = eduTeacherService.getTeacherByUsername(s);
        EduStudent student = eduStudentService.getStudentByUsername(s);
        if (null == teacher && null == student) {
            return null;
        } else {
            if (null != teacher) {
                return teacher;
            } else {
                return student;
            }
        }
    }
}
